package com.ylm.wurao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ylm.wurao.model.User;
import com.ylm.wurao.service.UserService;

@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @PostMapping("/add.do")
    public int addUser(User user){
        return userService.addUser(user);
    }

    @ResponseBody
    @GetMapping("/all.do")
    public Object findAllUser(
            @RequestParam(name = "pageNum", required = false, defaultValue = "1")
                    int pageNum,
            @RequestParam(name = "pageSize", required = false, defaultValue = "10")
                    int pageSize){
        return userService.findAllUser(pageNum,pageSize);
    }
    
    @ResponseBody
    @GetMapping("/index.do")
    public Object index(){
    	List<User> user=userService.selectUsers();
        return user;
    }
    
    /**
	 * 网页根目录请求
	 * @return
	 */
	@RequestMapping("/home.do")
	public ModelAndView root(){
		ModelAndView mav=new ModelAndView();
		mav.addObject("title", "wurao_进阶之路");
		mav.setViewName("index");
		return mav;
	}
}


